package cn.leonis.leetcode;

/**
 * @Author Tobi
 * @Date 2021-07-23 下午4:33
 * 合并两个有序链表
 */
public class MergeTwoSortedLinkedListSolution {

    public static void main(String[] args) {

    }

    /**
     * 解法一：递归
     * @param l1
     * @param l2
     * @return
     */
    public ListNode1 mergeTwoLists(ListNode1 l1, ListNode1 l2) {
        if (l1 == null) {
            return l2;
        } else if (l2 == null) {
            return l1;
        } else if (l1.val < l2.val) {
            l1.next = mergeTwoLists(l1.next, l2);
            return l1;
        } else {
            l2.next = mergeTwoLists(l2.next, l1);
            return l2;
        }
    }

    /**
     * 解法二：
     * @param l1
     * @param l2
     * @return
     */
    public ListNode1 mergeTwoLists1(ListNode1 l1, ListNode1 l2) {
        return null;
    }
}
